const app = getApp()
let host = app.globalData.host;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    marketIcon: '../../images/market.png',
    addIcon: '../../images/addicon1.png',
    soleOVerIcon: '../../images/saleover.png',
    navLeftItems: [
      {
        id: '0',
        icon: '../../images/fruiticon.png',
        productTypeName: '水果'
      },
      {
        id: '1',
        icon: '../../images/vegicon.png',
        productTypeName: '蔬菜'
      },
      {
        id: '2',
        icon: '../../images/meaticon.png',
        productTypeName: '肉蛋'
      },
      {
        id: '3',
        icon: '../../images/othericon.png',
        productTypeName: '其他'
      }
    ],
    curNav: 0,
		curIndex: 0

  },
  //选择分类
  switchRightTab: function(e) {
    let id = e.target.dataset.id
    console.log(e)
    this.setData({
      curNav: id,
      curIndex: id
  })
},
  addGoods:function(e){
    wx.navigateTo({
     url: '../addGoods/addGoods?goodsType='+e.target.dataset.id
    })
  },
  editGoods:function(e){
    wx.navigateTo({
      url: '../editGoods/editGoods?goodsId='+e.target.dataset.id
    })
  },
  addChartFromClassify:function(e){
    wx.request({
      url: host+'/addCart?goodsId='+e.target.dataset.id + '&userId=123',
      method:"GET",
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },success (res) {
        console.log(res)
      },
      fail (error){
        console.log("失败")
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let pageNum = options.curIndex
    if (pageNum == null) {
      pageNum = 0
    }
    let that = this
    wx.request({
      url: '/showAllGoods',
      method: "GET",
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },success (res) {
        console.log(pageNum)
        console.log(res)
        that.setData({
          navRightItems: res.data,
          curNav: pageNum,
          curIndex: pageNum
        })
      },
      fail (error){
        console.log("失败")
      }
    })
  }
})